﻿#pragma once

#include <QApplication>
#include <QMainWindow>
#include <QListWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include "qcustomplot.h"
#include <QVector>
#include <QStringList>
#include <QWidget>
#include <QCheckBox>
#include <QDoubleSpinBox>
#include <QHBoxLayout>


class CheckBoxDoubleSpinBox : public QWidget {
    Q_OBJECT
public:
    CheckBoxDoubleSpinBox(QString cbStr, QWidget* parent = nullptr) : QWidget(parent) {
        // 创建 QCheckBox 和 QDoubleSpinBox
        checkBox = new QCheckBox(cbStr, this);
        checkBox->setChecked(false);
        doubleSpinBox = new QDoubleSpinBox(this);
        doubleSpinBox->setRange(-1000000.0, 10000000.0);
        doubleSpinBox->setValue(0.0);
        doubleSpinBox->setSingleStep(0.1);
        doubleSpinBox->setDecimals(4);

        // 创建布局并添加控件
        auto* layout = new QVBoxLayout(this);
        layout->addWidget(checkBox);
        layout->addWidget(doubleSpinBox);
        this->setLayout(layout);

        // 连接信号和槽
        connect(checkBox, &QCheckBox::stateChanged, this, &CheckBoxDoubleSpinBox::onCheckBoxStateChanged);
    }



public slots:
    void onCheckBoxStateChanged(int state) {
        // 根据 QCheckBox 的状态来控制 QDoubleSpinBox 的可见性
        doubleSpinBox->setVisible(state == Qt::Checked);
    }

public:
    QCheckBox* checkBox;
    QDoubleSpinBox* doubleSpinBox;
};


class ScatterPlotWidget : public QWidget {
    Q_OBJECT

public:
    ScatterPlotWidget(const QVector<QVector<double>>& data, const QStringList& columnNames, QWidget* parent = nullptr);

private slots:
    void plotScatter();
    void yRangeChanged(double value);

private:
    void setupUI();
    void populateListWidgets();

private:
    QListWidget* xListWidget;
    QListWidget* yListWidget;
    QListWidget* colorListWidget;
    QCustomPlot* customPlot;
    QPushButton* plotButton;
    CheckBoxDoubleSpinBox* cbdspbYMin, * cbdspbYMax;
    QSpinBox* spbPointSize, *spbFontSize;
    const QVector<QVector<double>>& columnData;
    const QStringList& columnNames;
};
